package com.young.jdbc.datasource;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * @Author: young
 * @Date: 2021-12-03 16:51
 * @Description: Druid(德鲁伊)数据库连接池的使用
 */
public class Druid_demo {
	@Test
	public void testDruid() throws Exception {
		Properties properties = new Properties();
		properties.load(new FileInputStream("src\\druid.properties"));

		// 创建指定参数的数据库连接池
		DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
		long start = System.currentTimeMillis();
		for (int i=0;i<5000;i++){
			Connection connection = dataSource.getConnection();
			// System.out.println("连接成功");
			connection.close();
		}
		long end = System.currentTimeMillis();
		System.out.println("druid连接池 耗时为"+(end-start));
	}
}
